package suites.tween {
	import org.flexunit.asserts.assertEquals;
	import org.splink.library.queue.QEvent;
	import org.splink.library.tween.sprop.ColorProp;
	import org.splink.library.tween.sprop.FilterProp;
	import org.splink.library.tween.sprop.ISpecialProp;
	import org.splink.library.tween.sprop.ScrollRectProp;

	import flash.filters.BlurFilter;
	import flash.geom.Rectangle;

	/**
	 * @author Max Kugland
	 */
	public class TweenSpecialPropertyTest extends AbstractTweenTest {

		[Test(async)]
		public function testSingleFilterProp() : void {
			handleAsync(500);
			_target.filters = [new BlurFilter(100, 0)];
			var p : ISpecialProp = new FilterProp(_target.filters[0]);
			_tween.add(FilterProp.BLUR_X, 0, NaN, p).duration(200);
			_tween.register(QEvent.COMPLETE, function(e : QEvent):void {
				assertEquals(0, BlurFilter(_target.filters[0]).blurX);
			});
			assertEquals(100, BlurFilter(_target.filters[0]).blurX);
			_tween.start();
		}

		[Test(async)]
		public function testSingleColorProp() : void {
			handleAsync(500);
			var p : ISpecialProp = new ColorProp(_target);
			_tween.add(ColorProp.COLOR, 0xff00ff, NaN, p).duration(200);
			_tween.register(QEvent.COMPLETE, function(e : QEvent):void {
				assertEquals(0xff00ff, _target.transform.colorTransform.color);
			});
			assertEquals(0, _target.transform.colorTransform.color);
			_tween.start();
		}

		[Test(async)]
		public function testSingleScrollRectProp() : void {
			handleAsync(500);
			_target.scrollRect = new Rectangle(0, 0, 100, 100);
			var p : ISpecialProp = new ScrollRectProp(_target);
			_tween.add(ScrollRectProp.Y, 100, NaN, p).duration(200);
			_tween.register(QEvent.COMPLETE, function(e : QEvent):void {
				assertEquals(100, _target.scrollRect.y);
			});
			assertEquals(0, _target.scrollRect.y);
			_tween.start();
		}

		[Test(async)]
		public function testMultiScrollRectProp() : void {
			handleAsync(500);
			_target.scrollRect = new Rectangle(0, 0, 100, 100);
			var p : ISpecialProp = new ScrollRectProp(_target);
			_tween.add(ScrollRectProp.X, 100, NaN, p);			_tween.add(ScrollRectProp.Y, 100, NaN, p);
			_tween.duration(200);
			_tween.register(QEvent.COMPLETE, function(e : QEvent):void {
				assertEquals(100, _target.scrollRect.x);				assertEquals(100, _target.scrollRect.y);
			});
			assertEquals(0, _target.scrollRect.x);			assertEquals(0, _target.scrollRect.y);
			_tween.start();
		}

		[Test(async)]
		public function testMultiFilterProp() : void {
			handleAsync(500);
			_target.filters = [new BlurFilter(100, 100)];
			var p : ISpecialProp = new FilterProp(_target.filters[0]);
			_tween.add(FilterProp.BLUR_X, 0, NaN, p);			_tween.add(FilterProp.BLUR_Y, 0, NaN, p);
			_tween.duration(200);
			_tween.register(QEvent.COMPLETE, function(e : QEvent):void {
				assertEquals(0, BlurFilter(_target.filters[0]).blurX);				assertEquals(0, BlurFilter(_target.filters[0]).blurY);
			});
			assertEquals(100, BlurFilter(_target.filters[0]).blurX);			assertEquals(100, BlurFilter(_target.filters[0]).blurY);
			_tween.start();
		}

		[Test(async)]
		public function testMultiProps() : void {
			handleAsync(500);
			
			_target.scrollRect = new Rectangle(0, 0, 100, 100);
			_target.filters = [new BlurFilter(100, 100)];
			_target.scrollRect = new Rectangle(0, 0, 100, 100);
			
			var sp : ISpecialProp = new ScrollRectProp(_target);
			var fp : ISpecialProp = new FilterProp(_target.filters[0]);
			var cp : ISpecialProp = new ColorProp(_target);
			
			_tween.add(FilterProp.BLUR_X, 0, NaN, fp);
			_tween.add(FilterProp.BLUR_Y, 0, NaN, fp);
			_tween.add(ScrollRectProp.X, 100, NaN, sp);
			_tween.add(ScrollRectProp.Y, 100, NaN, sp);
			_tween.add(ColorProp.COLOR, 0xff00ff, NaN, cp);
			_tween.duration(200);
			_tween.register(QEvent.COMPLETE, function(e : QEvent):void {
				assertEquals(0, BlurFilter(_target.filters[0]).blurX);
				assertEquals(0, BlurFilter(_target.filters[0]).blurY);
				assertEquals(100, _target.scrollRect.x);
				assertEquals(100, _target.scrollRect.y);
				assertEquals(0xff00ff, _target.transform.colorTransform.color);
			});
			
			assertEquals(0, _target.transform.colorTransform.color);
			assertEquals(0, _target.scrollRect.x);
			assertEquals(0, _target.scrollRect.y);
			assertEquals(100, BlurFilter(_target.filters[0]).blurX);
			assertEquals(100, BlurFilter(_target.filters[0]).blurY);
			_tween.start();
		}

		[Test(async)]
		public function testStartValue() : void {
			handleAsync(500);
			
			var cp : ISpecialProp = new ColorProp(_target);
			_tween.add(ColorProp.COLOR, 0xff00ff, 0xff0000, cp).duration(200);
			_tween.register(QEvent.COMPLETE, function(e : QEvent) : void {
				assertEquals(0xff00ff, _target.transform.colorTransform.color);
			});
			_tween.start();
			assertEquals(0xff0000, _target.transform.colorTransform.color);
		}
	}
}
